// pages/peccancy/cart-list.js
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        page: 1,
        total: 2,
        loading: false,
        cartList: []
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
    
    },
	onShow(){
		this.loadData()
	},
    loadData() {
        let {
            page = 1, total = 2, loading = false, cartList = [], rows = 10
        } = this.data
        if (cartList.length >= total || loading) return
        this.setData({
            loading: true
        })
		wx.showLoading({
			title: '加载中...',
		})
        app.http.post('rest/car/queryByList.do', {
            data: {
                page,
                rows
            }
        }).then(res => {
            page++
            total = res.obj.total
            loading = false
            cartList.push(...res.obj.rows)
            this.setData({
                page,
                total,
                loading,
                cartList
            })
            wx.hideLoading()
            wx.stopPullDownRefresh()
        }).catch(err => {
            wx.hideLoading()
            app.wxToast.error(err.data.msg)
        })
    },
    
    onPullDownRefresh: function() {
        this.setData({
            page: 1,
            total: 2,
            loading: false,
            cartList: []
        })
        this.loadData()
    },

    onReachBottom: function() {
        this.loadData()
    },

})